import pygame.font

class Label:
    '''游戏中显示文字的组件'''

    def __init__(self,ai_game,position) -> None:
        '''初始化文字组件'''
        self.screen = ai_game.screen
        self.screen_rect = self.screen.get_rect()
        self.setting = ai_game.setting
        self.position = position

        self.text_color = (30,30,30)
        self.font = pygame.font.SysFont(None, 28)
        self.set_text()

    # 显示文本，并指定位置
    def set_text(self, text=0): 
        '''设置得分信息'''
        text_str = str(text)
        self.label_render = self.font.render(text_str, True, self.text_color, self.setting.bg_color)
        self.label_rect = self.label_render.get_rect()
        if self.position == 'right':
            self.label_rect.right = self.screen_rect.right - 20
        if self.position == 'center':
            self.label_rect.midtop= self.screen_rect.midtop
        if self.position == 'left':
            self.label_rect.left= self.screen_rect.left + 20
        self.label_rect.top = 10

    def show_text(self):
        '''在屏幕上显示得分'''
        self.screen.blit(self.label_render, self.label_rect)




    

        